package org.component 
{
	import com.utils.slider.ListIceSlider;
	import flash.display.MovieClip;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import org.component.item.ClistItem;
	/**
	 * ...
	 * @author ...
	 */
	
	[Event(name = "list_select", type = "org.component.events.ListEvent")]
	[Event(name = "list_select_room", type = "org.component.events.ListEvent")]
	
	
	public class Clist extends EventDispatcher
	{
		
		private var _classItem:Class = null;      
		
		
		private var _column:int = 1;
		
		private var _row:int = 1;
		
		private var _itemHeight:Number = 0;    
		
		private var _spaceHeight:Number = 0;
		
		private var _assest:MovieClip = null;
		
		private var _listView:MovieClip = null;
		
		private var _items:Array = null;
		
		private var _listDataArr:Array = null;
		
		
		
		public function Clist(ui:MovieClip = null, item:Class = null, listDataArr:Array = null, column:int=1, row:int=1, itemHeight:Number = 0, spaceHeight:Number=1) 
		{
			_assest = ui;
			_classItem = item;
			_itemHeight = itemHeight;
			_spaceHeight = spaceHeight;
			_row = row;
			_column = column;
			
			_listDataArr = listDataArr;
			
			initialization();
			configEventListeners();
		}
		
		/**
		 * 初始化
		 */
		protected function initialization():void
		{
			_listView = _assest["listView"];
			
			_items = [];
			
			for (var i:int = 0; i < _column*_row; i++)
			{
				var item:ClistItem = new _classItem(_listView["item" + i]) as ClistItem;
				item.setLabel(_listDataArr[i]);
				item.getSubject(this);
				_items[_items.length] = item;
				
				item = null;
			}
		}
		/**
		 * 注册监听
		 */
		protected function configEventListeners():void
		{
			
		}
		
		public function isShow():Boolean { return _listView.visible; }
		
		public function show():void
		{
			_listView.visible = true;
		}
		
		public function hide():void
		{
			_listView.visible = false;
		}
		
		private var _list:Array = null;
		
		private var _clen:int = -1;
		/**
		 * 
		 * @param	list
		 */
		public function update(list:Array = null):void
		{
			selectIndex = -1;
			selectItem = null;
			_list = list?list:[];
			_clen = Math.ceil(_list.length / _column);
			_index = -1;
			_listDataArr = list;
			
			
		}
		
		private var _selectItem:ClistItem = null;
		public function get selectItem():ClistItem { return _selectItem; }
		public function set selectItem(value:ClistItem):void
		{
			if (_selectItem)
			{
				_selectItem.select = false;
			}
			_selectItem = value;
			if (_selectItem)
			{
				_selectItem.select = true;
			}
		}
		
		private var _selectIndex:int = -1;
		public function get selectIndex():int { return _selectIndex; }
		public function set selectIndex(value:int):void
		{
			_selectIndex = value;
		}
		
		private var _index:int = -1;
		public function get index():int { return _index; }
		public function set index(value:int):void
		{
			if (_index == value) return;
			
			_index = value;
		}
		
		/**
		 * 
		 * @param	type 
		 * @param	value
		 * @return
		 */
		
		public function getTypeByItem(type:String = "", value:int = -1):ClistItem
		{
			for each(var item:ClistItem in _items)
			{
				if (item.listdata&&item.listdata[type] == value) return item;
				
			}
			return null;
		}
		
		public function get listDataArr():Array
		{
			return _listDataArr;
		}
	}

}